package com.cameron.serviceedu.controller;


import com.cameron.serviceedu.entity.EduChapter;
import com.cameron.serviceedu.entity.dto.ChapterDto;
import com.cameron.serviceedu.service.EduChapterService;
import com.cameron.utils.Result;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author cameron
 * @since 2022-06-17
 */
@Api("章节模块")
@RestController
@RequestMapping("/service/edu-chapter")
@CrossOrigin
public class EduChapterController {

    @Resource
    private EduChapterService chapterService;

    @GetMapping("getAll/{courseId}")
    public Result getAll(@PathVariable String courseId) {
        List<ChapterDto> chapterDtoList = chapterService.getAll(courseId);
        return Result.ok().data("chapterList", chapterDtoList);
    }

    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody EduChapter chapter) {
        return chapterService.saveOrUpdate(chapter) ? Result.ok() : Result.error();
    }

    @GetMapping("{chapterId}")
    public Result getById(@PathVariable String chapterId) {
        return Result.ok().data("chapter", chapterService.getById(chapterId));
    }

    @DeleteMapping("{chapterId}")
    public Result delChapter(@PathVariable String chapterId) {
        return chapterService.delChapter(chapterId);
    }
}

